package com.ilop.sthome.data.enums;

import android.content.Context;

import com.siterwell.familywellplus.R;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author skygge
 * @date 2020-01-01.
 * GitHub：javofxu@github.com
 * email：skygge@yeah.net
 * description：所有产品
 */

public enum SmartDevice {

    // 门磁
    EE_DEV_DOOR(CellsEnum.SMART_DOOR, CellsEnum.SMART_DOOR_COMMON, R.string.door, R.mipmap.gs320d, R.drawable.config_door),

    //智能插座
    EE_DEV_SOCKET(CellsEnum.SMART_SOCKET, CellsEnum.SMART_SOCKET_COMMON, R.string.socket, R.mipmap.gs350, R.drawable.config_socket),

    //人体移动探测器
    EE_DEV_PIR(CellsEnum.SMART_PIR, CellsEnum.SMART_PIR_COMMON, R.string.pir, R.mipmap.gs300d, R.drawable.config_pir),

    //SOS按钮
    EE_DEV_SOS(CellsEnum.SMART_SOS, CellsEnum.SMART_SOS_COMMON, R.string.soskey, R.mipmap.gs390, R.drawable.config_sos),

    //SM报警器
    EE_DEV_SM_ALARM(CellsEnum.SMART_SM_ALARM, CellsEnum.SMART_SM_ALARM_COMMON, R.string.smalarm, R.mipmap.gs530, R.drawable.config_sm),

    //CO报警器
    EE_DEV_CO_ALARM(CellsEnum.SMART_CO_ALARM, CellsEnum.SMART_CO_ALARM_COMMON, R.string.coalarm, R.mipmap.gs816, R.drawable.config_co),

    //水感报警器
    EE_DEV_WT_ALARM(CellsEnum.SMART_WT_ALARM, CellsEnum.SMART_WT_ALARM_COMMON, R.string.wt, R.mipmap.gs156, R.drawable.config_water),

    //温湿度探测器
    EE_DEV_TH_CHECK(CellsEnum.SMART_TH_CHECK, CellsEnum.SMART_TH_COMMON, R.string.thcheck, R.mipmap.gs240d, R.drawable.config_thcheck),

    //按键
    EE_DEV_BUTTON(CellsEnum.SMART_BUTTON, CellsEnum.SMART_BUTTON_COMMON, R.string.button, R.mipmap.gs585, R.drawable.config_button),

    //复合型报警器
    EE_DEV_SX_SM_ALARM(CellsEnum.SMART_SX_ALARM, CellsEnum.SMART_SX_ALARM_COMMON, R.string.cxsmalarm, R.mipmap.gs592, R.drawable.config_cxsm),

    //燃气报警器
    EE_DEV_GAS_ALARM(CellsEnum.SMART_GAS_ALARM, CellsEnum.SMART_GAS_ALARM_COMMON, R.string.gasalarm, R.mipmap.gs870w, R.drawable.config_gas),

    //新燃气报警器
    EE_DEV_NEW_GAS_ALARM(CellsEnum.SMART_NEW_GAS_ALARM, CellsEnum.SMART_NEW_GAS_ALARM_COMMON, R.string.gasalarm, R.mipmap.gs871, R.drawable.config_co_gas),

    //CO&GAS报警器
    EE_DEV_CO_GAS_ALARM(CellsEnum.SMART_CO_GAS_ALARM, CellsEnum.SMART_CO_GAS_ALARM_COMMON, R.string.co_and_gas_alarmer, R.mipmap.gs871, R.drawable.config_co_gas),

    //热感报警器
    EE_DEV_THERM_ALARM(CellsEnum.SMART_THERM_ALARM, CellsEnum.SMART_THERM_ALARM_COMMON, R.string.thermalalarm, R.mipmap.gs412, R.drawable.config_hot),

    //震动闪光报警器
    EE_DEV_FLASH_ALARM(CellsEnum.SMART_FLASH_ALARM, CellsEnum.SMART_FLASH_ALARM_COMMON, R.string.vibration_flash_compound_alarm, R.mipmap.gs163, R.drawable.config_flash),

    //机械手
    EE_DEV_MANIPULATOR(CellsEnum.SMART_MANIPULATOR, CellsEnum.SMART_MANIPULATOR_COMMON, R.string.manipulator, R.mipmap.gs970, R.drawable.config_manipulator),

    //电磁阀
    EE_DEV_SOLENOID_VALVE(CellsEnum.SMART_SOLENOID_VALVE, CellsEnum.SMART_SOLENOID_VALVE_COMMON, R.string.solenoid_valve_controller, R.mipmap.gs972, R.drawable.config_solenoid_valve),

    //场景开关
    EE_DEV_MODE_BUTTON(CellsEnum.SMART_SCENE_SWITCH, CellsEnum.SMART_SCENE_SWITCH_COMMON, R.string.mode_button, R.mipmap.gs584, R.drawable.config_mode_button),

    //开关模块
    EE_DEV_LIGHTING_MODULE(CellsEnum.SMART_LIGHTING_MODULE, CellsEnum.SMART_LIGHTING_MODULE_COMMON, R.string.lamp_model, R.mipmap.gs344, R.drawable.config_switch_mode),

    //门锁
    EE_DEV_LOCK(CellsEnum.SMART_DOOR_LOCK, CellsEnum.SMART_DOOR_LOCK_COMMON, R.string.lock, R.mipmap.gs920, R.drawable.config_lock),

    //温控器
    EE_TEMP_CONTROL(CellsEnum.SMART_CONTROL, CellsEnum.SMART_CONTROL_COMMON, R.string.temp_controler, R.mipmap.gs361, R.drawable.config_temp),

    //室外警笛
    EE_TEMP_OUTDOOR_SIREN(CellsEnum.SMART_OUTDOOR, null, R.string.outdoor_siren, R.mipmap.gs380, R.drawable.config_shiwai),

    //网关
    EE_SIMULATE_GATEWAY(CellsEnum.SMART_GATEWAY, null, R.string.ali_gateway, R.mipmap.gs198, R.drawable.config_moren),

    //摄像头
    EE_SIMULATE_IPC(CellsEnum.SMART_CAMERA, null, R.string.ali_camera, R.mipmap.gs290, R.drawable.config_moren),

    //定时
    EE_SIMULATE_TIMER(CellsEnum.SMART_TIMER, null, R.string.timer, R.mipmap.timing_64, R.drawable.config_moren),

    //点击执行
    EE_SIMULATE_CLICK(CellsEnum.SMART_CLICK, null, R.string.clickTo, R.mipmap.manual_clicking_64, R.drawable.config_moren),

    //延时
    EE_SIMULATE_DELAY(CellsEnum.SMART_DELAY, null, R.string.delay, R.mipmap.delayed_64, R.drawable.config_moren),

    //手机推送
    EE_SIMULATE_PHONE(CellsEnum.SMART_PHONE, null, R.string.phone, R.mipmap.mobile_phone_64, R.drawable.config_moren),

    //未知设备
    EE_DEV_UN_KNOW(CellsEnum.SMART_UN_KNOW, null, R.string.unamed, R.mipmap.default_pic_152, R.drawable.config_moren);

    private String[] devType;
    private String[] devCommon;
    private int devResId;
    private int drawResId;
    private int drawGuideResId;

    SmartDevice(String[] devType, String[] devCommon, int resId, int iconId, int guideResId) {
        this.devType = devType;
        this.devCommon = devCommon;
        this.devResId = resId;
        this.drawResId = iconId;
        this.drawGuideResId = guideResId;
    }

    /**
     * 获取设备类型的字符串ID
     * @return 设备类型字符串ID
     */
    public int getTypeStrId() {
        return this.devResId;
    }

    /**
     * 获取设备图标的资源ID
     * @return
     */
    public int getDrawableResId() {
        return this.drawResId;
    }

    /**
     * 获取设备类型的索引号
     * @return
     */
    public String[] getDevType() {
        return this.devType;
    }

    /**
     * 获取设备类型的常用功能
     * @return
     */
    public String[] getDevCommon() {
        return devCommon;
    }

    /**
     * 获取设备类型的图片资源
     * @return
     */
    public int getDrawGuideResId() {
        return drawGuideResId;
    }

    /**
     * 查询相关设备
     * @param devType 设备类型
     * @return
     */
    public static SmartDevice getType(String devType) {
        for (SmartDevice smartDevice : SmartDevice.values()) {
            if (Arrays.asList(smartDevice.devType).contains(devType)){
                return smartDevice;
            }
        }
        return EE_DEV_UN_KNOW;
    }

    public static List<String> getTypeList(Context context, String name) {
        List<String> deviceType = new ArrayList<>();
        for (SmartDevice smartDevice : SmartDevice.values()) {
            if (context.getString(smartDevice.devResId).equals(name)){
                deviceType.addAll(Arrays.asList(smartDevice.devType));
            }
        }
        return deviceType;
    }
}
